//
//  FKDownloadListSwitcher.m
//  FK
//
//  Created by handy wang on 6/8/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "FKDownloadListSwitcher.h"
#import "FKDownloadViewController.h"
#import <QuartzCore/QuartzCore.h>

#define SELF_WIDTH                                          (320.0f)
#define SELF_HEIGHT                                         (44.0f)

@interface FKDownloadListSwitcher()

- (void)setDownloadingListViewMode;

- (void)setDownloadedListViewMode;

@end


@implementation FKDownloadListSwitcher

- (id)initWithIDelegate:(id)delegateParam {
    self = [super initWithFrame:CGRectMake(0, 0, SELF_WIDTH, SELF_HEIGHT)];
    if (self) {
        _delegate = delegateParam;
        
        _downloadingBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        _downloadingBtn.frame = CGRectMake(0, 0, SELF_WIDTH/2.0f, SELF_HEIGHT);
        [_downloadingBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_downloadingBtn setTitle:@"正在下载" forState:UIControlStateNormal];
        _downloadingBtn.layer.borderColor = [UIColor blackColor].CGColor;
        _downloadingBtn.layer.borderWidth = 0.5;
        [_downloadingBtn addTarget:self action:@selector(setDownloadingListViewMode) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_downloadingBtn];
        
        _downloadedBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        _downloadedBtn.frame = CGRectMake(SELF_WIDTH/2.0f, 0, SELF_WIDTH/2.0f, SELF_HEIGHT);
        [_downloadedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_downloadedBtn setTitle:@"已下载" forState:UIControlStateNormal];
        _downloadedBtn.layer.borderColor = [UIColor blackColor].CGColor;
        _downloadedBtn.layer.borderWidth = 0.5;
        [_downloadedBtn addTarget:self action:@selector(setDownloadedListViewMode) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_downloadedBtn];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc {
    [_downloadingBtn release];
    _downloadingBtn = nil;
    
    [_downloadedBtn release];
    _downloadedBtn = nil;
    
    [super dealloc];
}

#pragma mark - Private methods implementation

- (void)setDownloadingListViewMode {
    if (_delegate && [_delegate respondsToSelector:@selector(setDownloadListViewMode:)]) {
        [_delegate setDownloadListViewMode:FKDownloadListViewDownloadingMode];
    }
}

- (void)setDownloadedListViewMode {
    if (_delegate && [_delegate respondsToSelector:@selector(setDownloadListViewMode:)]) {
        [_delegate setDownloadListViewMode:FKDownloadListViewDownloadedMode];
    }
}

@end